home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / acpi / panabright.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2008-10-14  |  1KB  |  49 lines

  1. #!/bin/sh
  2.  
  3. test -f /usr/share/acpi-support/key-constants || exit 0
  4.  
  5. # default span value
  6. SPAN=1
  7.  
  8. # check power state
  9.  
  10. STATE=`grep -c off-line /proc/acpi/ac_adapter/*/state`
  11. if [ "x$STATE" = "x0" ]
  12.    then
  13.    INTERFACE="ac_brightness"
  14. else
  15.    INTERFACE="dc_brightness"
  16. fi
  17.  
  18. # get brightness parameters
  19.  
  20. BRIGHTNESS=$(( `cat /proc/acpi/pcc/$INTERFACE` ))
  21. MAXBRIGHT=$(( `cat /proc/acpi/pcc/"$INTERFACE"_max` ))
  22. MINBRIGHT=$(( `cat /proc/acpi/pcc/"$INTERFACE"_min` ))
  23.  
  24. # adjust span so that there are 10 brightness increments
  25.  
  26. WIDTH=$(( $MAXBRIGHT - $MINBRIGHT ))
  27. SPAN=$(( $WIDTH / 10 ))
  28.  
  29. if [ "x$1" = "xdown" ]; then
  30.    LIMIT=$(( $MINBRIGHT + $SPAN ))
  31.    if [ $BRIGHTNESS -gt $LIMIT ]; then
  32.       BRIGHTNESS=$(( $BRIGHTNESS - $SPAN ))
  33.  
  34.    else
  35.       BRIGHTNESS=$(( $MINBRIGHT ))
  36.    fi
  37.    echo $BRIGHTNESS > /proc/acpi/pcc/$INTERFACE
  38. elif [ "x$1" = "xup" ]; then
  39.    LIMIT=$(( $MAXBRIGHT - $SPAN ))
  40.    if [ $BRIGHTNESS -lt $LIMIT ]; then
  41.       BRIGHTNESS=$(( $BRIGHTNESS + $SPAN ))
  42.    else
  43.       BRIGHTNESS=$(( $MAXBRIGHT ))
  44.    fi
  45.    echo $BRIGHTNESS > /proc/acpi/pcc/$INTERFACE
  46. else
  47.    echo >&2 Unknown argument $1
  48. fi
  49.